package bean;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Enumeration;

import com.oreilly.servlet.MultipartRequest;
import com.oreilly.servlet.multipart.DefaultFileRenamePolicy;


public class MemberDTO {
	
	private MemberVo vo;
	private MemberVo2 vo2;
	private Connection conn;
	
	public MemberDTO() {
		conn=new MyOracle().getConn();
	}

	public boolean login(){
		boolean b=false;
		try {
			String sql="select mid, pwd from member where mid=? and pwd=?";
			PreparedStatement pst=conn.prepareStatement(sql);
			pst.setString(1, vo.getMid());
			pst.setString(2, vo.getPwd());
			
			ResultSet rs=pst.executeQuery();
			if(rs.next()) b=true;
			
			pst.close();
			conn.close();
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return b;
	}
	
	public void insert2(){
		
	}
	
	public Connection getConn() {
		return conn;
	}

	public void setConn(Connection conn) {
		this.conn = conn;
	}

	public MemberVo getVo() {
		return vo;
	}

	public void setVo(MemberVo vo) {
		this.vo = vo;
	}

	public MemberVo2 getVo2() {
		return vo2;
	}

	public void setVo2(MemberVo2 vo2) {
		this.vo2 = vo2;
		int size=1024*1024*10;
		String saveDir="C:/Users/jhta/Documents/java workspace/Hello/WebContent/memberPhoto/";
		String oriFile="";
		String sysFile="";
		MultipartRequest multi=null;
		try {
			multi=new MultipartRequest(vo2.getRequst(), saveDir, size, "utf-8", new DefaultFileRenamePolicy());
			Enumeration files =multi.getFileNames();
			String tempFile=(String)files.nextElement();
			oriFile=multi.getOriginalFileName(tempFile);
			sysFile=multi.getFilesystemName(tempFile);
						
			vo2.setMid(multi.getParameter("mid"));
			vo2.setIrum(multi.getParameter("irum"));
			vo2.setPwd(multi.getParameter("pwd"));
			vo2.setPhoto(sysFile);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	
	
}
